<?php
/**
 * 说明：前台文章控制器
 * 提醒：A点、B点：控制某大栏目文章列表显示整站/只显示分站
 *
 */
class Article extends Controller {

	function Article()
	{
		parent::Controller();
		$this->load->helper('cookie');
		$this->load->library('myfunction');   //载入自定义函数库
		$this->load->model('access_model');  //载入访客接入判断模型
		$this->load->model('article_model');  //载入文章模型
	}

	function list_article() {
		$bc_id=intval($this->uri->segment(3,1));//限制整型bc_id,如果没有URI参数，则默认$bc_id=1
		$sc_id=intval($this->uri->segment(4,0));//限制整型sc_id,如果没有URI参数，则默认$sc_id=0
		if ((!isset($_SESSION['siteinfo'])) || (count($_SESSION['siteinfo'])!=3)) {	//如果session里没有写入siteinfo信息
			$this->access_model->judgearea(); //判断访客地区（已写入session和cookie信息）
		}
		$data['baseurl']=base_url();
		$data['area']=$_SESSION['siteinfo']['area'];
		$data['areacode']=$_SESSION['siteinfo']['areacode'];
		$data['site']=$_SESSION['siteinfo']['site'];
		$data['head_info']="<link href=\"css/common.css\" type=\"text/css\" rel=\"stylesheet\"><link href=\"css/article.css\" type=\"text/css\" rel=\"stylesheet\">";//网页head区域信息
		$data['web_title']="好医生导医网——".$data['area']."站";//浏览器标题
		$this->load->view('topbar_view',$data);
		$this->load->view('head_view',$data);
		//输出主菜单内容
		$data['bignav']='<li class="first current"><a target="_self" href="/"><span>首页</span></a></li>';
		$data['bignav']=$data['bignav'].'<li class="current-next"><a target="_self" href="hospital/native"><span>合作医院</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="hospital/depttype"><span>推荐专科</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="#"><span>疾病指南</span></a></li>';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="exam"><span>优惠体检</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="#"><span>大河名医馆</span></a></li>';
		//输出副菜单内容
		$data['smallnav']='<li class="first"><a target="_self" href="#"><span>服务预约</span></a></li>';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="#"><span>在线购卡</span></a></li>	';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="service"><span>客服中心</span></a></li>	';
		//输出mini菜单
		$data['mininav']='<li class="first"><a target="_self" href="article/list_article/1"><span>新闻公告</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/2"><span>医院资讯</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/3/1"><span>就医指南</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/3/2"><span>生活保健</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/3/3"><span>疾病防治</span></a></li>';
		$this->load->view('nav_view',$data);
		//输出当前位置
		$bcname=$this->article_model->get_onebigclass_info($bc_id);
		$data['location']='<a href="'.base_url().'" target="_self" >首页</a> >> '.$bcname['bc_name'];
		//输出文章列表内容
		if($bc_id!=2) { //如果输出的不是“医院资讯”栏目（医院咨询bc_id为2）--------------------------------------------------------------------------A
			$acode='ALL';
		}else{
			$acode=$data['areacode'];
		}
		$page_num = '3';//每页的数据
		$total_nums=$this->article_model->list_article_get_num($acode,$bc_id,$sc_id);//读取文章总数
		if($total_nums==0) {
			$error['detail']="此栏目目前尚未完成建设！正在转回主页...";
			$error['min']=3;
			$error['url']=base_url();
			$this->load->view('manage/errormsg_view',$error);
		}else{
			$list_article = $this->article_model->list_article_get_list($acode,$bc_id,$sc_id,$page_num,intval($this->uri->segment(5)));
			//截取标题字符串
			$c=count($list_article)-1;
			for($i=0;$i<=$c;$i++) {
				$list_article[$i]['summary']=$this->myfunction->trimmed_title($list_article[$i]['summary'],80);//截取长字符串
			}
			$hotlist = $this->article_model->list_article_get_hot($acode,$bc_id,$sc_id,'10');//读取热门排行，默认10条
			//截取标题字符串
			$c=count($hotlist)-1;
			for($i=0;$i<=$c;$i++) {
				$hotlist[$i]['tit']=$this->myfunction->trimmed_title($hotlist[$i]['title'],12);//截取长字符串
			}
			$data['num']=$total_nums;
			$this->load->library('pagination');
			$config['base_url'] = base_url().'article/list_article/'.$bc_id.'/'.$sc_id;
			$config['uri_segment'] = 5;
			$config['total_rows'] = $total_nums;//总共多少条数据
			$config['per_page'] = $page_num;//每页显示几条数据
			$config['first_link'] = '首页';
			$config['first_tag_open'] = '<li>';//“第一页”链接的打开标签。
			$config['first_tag_close'] = '</li>';//“第一页”链接的关闭标签。
			$config['last_link'] = '尾页';//你希望在分页的右边显示“最后一页”链接的名字。
			$config['last_tag_open'] = '<li>';//“最后一页”链接的打开标签。
			$config['last_tag_close'] = '</li>';//“最后一页”链接的关闭标签。
			$config['next_link'] = '下一页';//你希望在分页中显示“下一页”链接的名字。
			$config['next_tag_open'] = '<li>';//“下一页”链接的打开标签。
			$config['next_tag_close'] = '</li>';//“下一页”链接的关闭标签。
			$config['prev_link'] = '上一页';//你希望在分页中显示“上一页”链接的名字。
			$config['prev_tag_open'] = '<li>';//“上一页”链接的打开标签。
			$config['prev_tag_close'] = '</li>';//“上一页”链接的关闭标签。
			$config['cur_tag_open'] = '<li class="current">';//“当前页”链接的打开标签。
			$config['cur_tag_close'] = '</li>';//“当前页”链接的关闭标签。
			$config['num_tag_open'] = '<li>';//“数字”链接的打开标签。
			$config['num_tag_close'] = '</li>';
			$this->pagination->initialize($config);
			$data['alist']=$list_article;
			$data['hotlist']=$hotlist;
			$this->load->view('list_article_view',$data);
		}
		$this->load->view('link_view',$data);
		//-----------------------------------------------foot_view--------------------------------------------------//
		$this->load->view('foot_view',$data);
	}

	function show_article() {
		$id = intval($this->uri->segment(3,0));
		if($id==0) {
			$error['detail']="未指定文章！正在转回主页...";
			$error['min']=3;
			$error['url']=base_url();
			$this->load->view('manage/errormsg_view',$error);
		}
		if ((!isset($_SESSION['siteinfo'])) || (count($_SESSION['siteinfo'])!=3)) {	//如果session里没有写入siteinfo信息
			$this->access_model->judgearea(); //判断访客地区（已写入session和cookie信息）
		}
		$data['baseurl']=base_url();
		$data['area']=$_SESSION['siteinfo']['area'];
		$data['areacode']=$_SESSION['siteinfo']['areacode'];
		$data['site']=$_SESSION['siteinfo']['site'];
		$data['head_info']="<link href=\"css/article.css\" type=\"text/css\" rel=\"stylesheet\"><script type=\"text/javascript\" src=\"/js/read_ajax.js\"></script>";//网页head区域信息
		$data['web_title']="好医生导医网——".$data['area']."站";//浏览器标题
		$this->load->view('topbar_view',$data);
		$this->load->view('head_view',$data);
		//输出主菜单内容
		$data['bignav']='<li class="first current"><a target="_self" href="/"><span>首页</span></a></li>';
		$data['bignav']=$data['bignav'].'<li class="current-next"><a target="_self" href="hospital/native"><span>合作医院</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="dept/depttype"><span>推荐专科</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="#"><span>疾病指南</span></a></li>';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="exam"><span>优惠体检</span></a></li>	';
		$data['bignav']=$data['bignav'].'<li><a target="_self" href="#"><span>大河名医馆</span></a></li>';
		//输出副菜单内容
		$data['smallnav']='<li class="first"><a target="_self" href="#"><span>服务预约</span></a></li>';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="#"><span>在线购卡</span></a></li>	';
		$data['smallnav']=$data['smallnav'].'<li><a target="_self" href="service"><span>客服中心</span></a></li>	';
		//输出mini菜单
		$data['mininav']='<li class="first"><a target="_self" href="article/list_article/1"><span>新闻公告</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/2"><span>医院资讯</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/3/1"><span>就医指南</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/3/2"><span>生活保健</span></a></li>';
		$data['mininav']=$data['mininav'].'<li><a target="_self" href="article/list_article/3/3"><span>疾病防治</span></a></li>';
		$this->load->view('nav_view',$data);
		$article=$this->article_model->get_one_article($id);
		if(empty($article)) {
			$error['detail']="未指定文章！正在转回主页...";
			$error['min']=3;
			$error['url']=base_url();
			$this->load->view('manage/errormsg_view',$error);
		}
		$this->article_model->add_hits($article['Id']);//点击量增加1
		$bc=$this->article_model->get_onebigclass_info($article['bc_id']);
		if($article['sc_id']!=0) {
			$sc=$this->article_model->get_onesmallclass_info($article['sc_id']);
			$data['location']="您的位置: <a href='".base_url()."' target='_self'>首页</a> >> ".$bc['bc_name']." >> <a href='article/list_article/".$article['bc_id']."/".$article['sc_id']."' target='_self'>".$sc['sc_name']."</a> >> ".$article['title'];
		}else{
			$data['location']="您的位置: <a href='".base_url()."' target='_self'>首页</a> >> <a href='article/list_article/".$article['bc_id']."' target='_self'>".$bc['bc_name']."</a> >> ".$article['title'];
		}
		$data['article']=$article;
		//输出文章列表内容
		$bc_id=$article['bc_id'];
		$sc_id=$article['sc_id'];
		if($bc_id!=2) { //如果输出的不是“医院资讯”栏目（医院咨询bc_id为2）--------------------------------------------------------------------------B
			$acode='ALL';
		}else{
			$acode=$data['areacode'];
		}
		//右侧热门同类新闻
		$hotlist = $this->article_model->list_article_get_hot($acode,$bc_id,$sc_id,'10');//读取热门排行，默认10条
			//截取标题字符串
			$c=count($hotlist)-1;
			for($i=0;$i<=$c;$i++) {
				$hotlist[$i]['tit']=$this->myfunction->trimmed_title($hotlist[$i]['title'],12);//截取长字符串
			}
		$data['hotlist']=$hotlist;
		$this->load->view('show_article_view',$data);
		$this->load->view('link_view',$data);
		//-----------------------------------------------foot_view--------------------------------------------------//
		$this->load->view('foot_view',$data);

	}
	
	function hit(){
		parse_str($_SERVER['QUERY_STRING'], $_GET);//启用GET方式
		$id=intval($this->input->get('id'));//文章ID
		$action = $this->input->get('action');//动作
		$read_id="0|";
		if(get_cookie('read')){
			$read_id=get_cookie('read',TRUE);//TURE参数为XSS过滤
			$id_array=explode("|",$read_id);
			if (in_array($id,$id_array)){
				echo 0;//如果已经评价过，则显示0
				exit();
				}
			}
		set_cookie('read',$read_id.'|'.$id,'2592000','.hysdy.com');
		$r=$this->article_model->hit($id,$action);//执行点击动作
		echo $r;
		}


	
}
?>